/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.util.HashSet;
import java.util.Set;


/**
 * Logical group of users, normally constrained to certain geographical locations. Persistent class, read-only.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class Organization implements java.io.Serializable {
	/**
	 * The identifier.
	 */
	private int id;

	/**
	 * The name.
	 */
	private String name;

	/**
	 * The set of provinces where an organization operates in.
	 */
	private Set<Province> provinces;

/**
   * Constructor.
   */
	public Organization() {
		provinces = new HashSet<Province>();
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public int getId() {
		return this.id;
	}

	/**
	 * Sets the identifier.
	 *
	 * @param id the identifier.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Retrieves the name.
	 *
	 * @return the name.
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the name.
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Retrieves the provinces.
	 *
	 * @return the provinces.
	 */
	public Set<Province> getProvinces() {
		return this.provinces;
	}

	/**
	 * Sets the provinces.
	 *
	 * @param provinces the provinces.
	 */
	public void setProvinces(final Set<Province> provinces) {
		this.provinces = provinces;
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof Organization)) {
			return false;
		}

		Organization that = (Organization)o;

		if(getId() != that.getId()) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return getId();
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("Organization");
		sb.append("{id=").append(getId());
		sb.append(", name='").append(getName()).append('\'');
		sb.append('}');

		return sb.toString();
	}
}
